//
//  SelfTableView.m
//  1gene
//
//  Created by 1jiyin on 16/3/17.
//  Copyright © 2016年 1jiyin. All rights reserved.
//

#import "SelfTableView.h"
#import "TieZiDetailModel.h"
#import "NSDictionary+NULLToNSString.h"
@interface SelfTableView ()
@property(nonatomic,copy)CommunityModel *model;
/*
 *用户Id
 */
@property(nonatomic,assign)NSInteger userId;

@property(nonatomic,assign)NSInteger cellIndex;

@property(nonatomic,copy)NSMutableArray *deleteArray;

@property(nonatomic,copy)NSDictionary *userDic;

@property(nonatomic,copy)NSMutableArray *tieziDataArray;


@property(nonatomic,assign)NSInteger deleteCellIndex;



//下一页
@property(nonatomic,copy)NSString *nextPageUrl;

@property(nonatomic,copy)NSMutableArray *allBiaoQianArray;

@end
@implementation SelfTableView
static int tiebaAnimationState=0;
-(instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style UserId:(NSInteger)userId
{
    if (self=[super initWithFrame:frame style:style]) {
        _userId=userId;
        self.delegate=self;
        self.dataSource=self;
        self.backgroundColor=[UIColor whiteColor];
        _dataArray=[NSMutableArray array];
        _deleteArray=[NSMutableArray array];
        self.tableFooterView=[UIView new];
        self.tableHeaderView=[self createTableHeaderView];
        self.separatorStyle=UITableViewCellSeparatorStyleNone;
        self.showsVerticalScrollIndicator=NO;
        self.header=[MJRefreshNormalHeader headerWithRefreshingBlock:^{
            [self getMyHttpData];
        }];
        
        self.footer=[MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
            [self getMoreData];
        }];
        [self getMyHttpData];
        
         [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(changeTableView:) name:@"ReloadSelfTableView" object:nil];

        UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
        lpgr.minimumPressDuration = 1; //seconds  设置响应时间
        [self addGestureRecognizer:lpgr]; //启用长按事件
        
               
        [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(startDeleteCell:) name:@"startDeleteCell" object:nil];
        
    }
    return self;
}
-(void)startDeleteCell:(NSNotification *)notify
{
    TieZiDetailModel *model=_dataArray[_deleteCellIndex];
    NSLog(@"dataArray==========%ld",_dataArray.count);
    [_dataArray removeObjectAtIndex:_deleteCellIndex];
    [self reloadData];
    [self deleteTopicHttpData:model.topic_id];
}


-(void)handleLongPress:(UILongPressGestureRecognizer *)gestureRecognizer  //长按响应函数
{
    CGPoint p = [gestureRecognizer locationInView:self];
    
    
    NSIndexPath *indexPath = [self indexPathForRowAtPoint:p];//获取响应的长按的indexpath
    if (indexPath == nil) {
        return;
    }else{
        NSLog(@"点击了哪一个cell======%ld",indexPath.row);
        _deleteCellIndex=indexPath.row;
        [[NSNotificationCenter defaultCenter]postNotificationName:@"deleteCellTopic" object:nil];
    }

   
    
    
}



//根据下一页的改动来修改tableView
-(void)changeTableView:(NSNotification *)notify
{
    //[[NSNotificationCenter defaultCenter]postNotificationName:@"ReloadTieBaTableView" object:nil userInfo:@{@"topic_id":[NSString stringWithFormat:@"%ld",_topic_id],@"is_like":[NSString stringWithFormat:@"%ld",zanState],@"like_num":_model.like_num}];
    NSDictionary *dic=notify.userInfo;
    NSLog(@"收到的通知==============%@",dic);
    NSInteger myTag=[self returnIndexPath:dic[@"topic_id"]];
    if (myTag<0) {
        return ;
    }else{
        
        
        
        UIImageView *imgView=(id)[self viewWithTag:[self returnIndexPath:dic[@"topic_id"]]];
        NSLog(@"=========%ld",imgView.tag);
        TieZiDetailModel *model1=_dataArray[imgView.tag];
        tiebaAnimationState=1;
        
        NSInteger zanState=[model1.is_like integerValue];
        CAKeyframeAnimation *k = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"];
        k.values = @[@(0.1),@(1.0),@(1.5)];
        k.keyTimes = @[@(0.0),@(0.5),@(0.8),@(1.0)];
        k.calculationMode = kCAAnimationLinear;
        if (zanState==0) {
            //点赞
            imgView.layer.contents=(id)[UIImage imageNamed:@"shequ_dianzan_yes"].CGImage;
            
            NSLog(@"点赞");
            
            NSDictionary *dic=_tieziDataArray[imgView.tag];
            NSInteger zanNumber=[dic[@"like_num"] integerValue];
            zanNumber+=1;
            [dic setValue:@"1" forKey:@"is_like"];
            [dic setValue:[NSString stringWithFormat:@"%ld",zanNumber] forKey:@"like_num"];
            TieZiDetailModel *model2=[[TieZiDetailModel alloc]initWithDictionary:dic];
            
            [_dataArray removeObjectAtIndex:imgView.tag];
            [_dataArray insertObject:model2 atIndex:imgView.tag];
            
            [_tieziDataArray removeObjectAtIndex:imgView.tag];
            [_tieziDataArray insertObject:dic atIndex:imgView.tag];
            
            //一个cell刷新
            NSIndexPath *indexPath=[NSIndexPath indexPathForRow:imgView.tag inSection:0];
            [self reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
            
            
        }else{
            //取消赞
            imgView.layer.contents=(id)[UIImage imageNamed:@"shequ_dianzan_no"].CGImage;
            NSLog(@"取消赞");
            
            NSDictionary *dic=_tieziDataArray[imgView.tag];
            [dic setValue:@"0" forKey:@"is_like"];
            NSInteger zanNumber=[dic[@"like_num"] integerValue];
            zanNumber-=1;
            [dic setValue:[NSString stringWithFormat:@"%ld",zanNumber] forKey:@"like_num"];
            TieZiDetailModel *model2=[[TieZiDetailModel alloc]initWithDictionary:dic];
            
            [_dataArray removeObjectAtIndex:imgView.tag];
            [_dataArray insertObject:model2 atIndex:imgView.tag];
            
            [_tieziDataArray removeObjectAtIndex:imgView.tag];
            [_tieziDataArray insertObject:dic atIndex:imgView.tag];
            
            //一个cell刷新
            NSIndexPath *indexPath=[NSIndexPath indexPathForRow:imgView.tag inSection:0];
            [self reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
            
        }
        [imgView.layer addAnimation:k forKey:@"SHOW"];
    }
}


//返回indexPath.row
-(NSInteger)returnIndexPath:(NSString *)topic_id
{
    for (int i=0; i<_dataArray.count; i++) {
        TieZiDetailModel *model=_dataArray[i];
        NSInteger modelId=[model.topic_id integerValue];
        NSInteger myId=[topic_id integerValue];
        if (modelId==myId) {
            return i;
        }
    }
    return 0;
}


static BOOL isEdited=YES;

//创建tableHeaderView
-(UIView *)createTableHeaderView
{
    UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, 130+75+30+2+30+1+20)];
    view.backgroundColor=[UIColor colorWithRed:235/255.0 green:235/255.0 blue:241/255.0 alpha:1];
    
//    UIView *backgroundView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, 120)];
//    backgroundView.backgroundColor=[UIColor colorWithRed:106/255.0 green:198/255.0 blue:223/255.0 alpha:1];
//    [view addSubview:backgroundView];
    
    
    UIImageView *backgroundImageView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, view.frame.size.width, 205)];
    backgroundImageView.image=[UIImage imageNamed:@"community-backgroundImage.png"];
    backgroundImageView.backgroundColor=[UIColor colorWithRed:106/255.0 green:198/255.0 blue:223/255.0 alpha:1];
    [view addSubview:backgroundImageView];
    
    //用户头像
    UIImageView *userHeadImageView=[[UIImageView alloc]initWithFrame:CGRectMake((self.frame.size.width-60)/2.0, 25, 60, 60)];
    [userHeadImageView sd_setImageWithURL:[NSURL URLWithString:_userDic[@"user_profile"][@"avatar_url"]] placeholderImage:[UIImage imageNamed:@"155x155-1.png"]];
    userHeadImageView.layer.cornerRadius=userHeadImageView.frame.size.width/2.0;
    userHeadImageView.layer.masksToBounds=YES;
    [view addSubview:userHeadImageView];

    NSData *data=[NSData dataWithContentsOfURL:[NSURL URLWithString:_userDic[@"user_profile"][@"avatar_url"]]];
    UIImage *myHeadImage=[UIImage imageWithData:data];
    userHeadImageView.image=myHeadImage;
    
    
    
    
    
    UIButton *userHeadBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    userHeadBtn.frame=CGRectMake((self.frame.size.width-60)/2.0, 25, 60, 60);
    [view addSubview:userHeadBtn];
    
    
    
    //性别
    UIImageView *sexImageView=[[UIImageView alloc]init];
    sexImageView.frame=CGRectMake((self.frame.size.width-20)/2.0, CGRectGetMaxY(userHeadBtn.frame), 20, 20);
    NSInteger sexState=[_userDic[@"user_profile"][@"sex"] integerValue];
    if (sexState==0) {
        sexImageView.image=[UIImage imageNamed:@"sex_man.png"];
    }else{
        sexImageView.image=[UIImage imageNamed:@"sex_woman.png"];
    }
    [view addSubview:sexImageView];
    
    //用户名
    UILabel *name=[[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(userHeadBtn.frame), sexImageView.frame.origin.x-10, 20)];
    name.textAlignment=NSTextAlignmentRight;
    name.text=_userDic[@"user_profile"][@"nikename"];
    name.font=[UIFont systemFontOfSize:15];
    name.textColor=[UIColor whiteColor];
    name.frame=CGRectMake(CGRectGetMaxX(name.frame)-[self calculateWidthWithLable:name], name.frame.origin.y, [self calculateWidthWithLable:name], name.frame.size.height);
    [view addSubview:name];
    
    if ([_userDic[@"user_profile"][@"nikename"] isKindOfClass:[NSNull class]]) {
        name.text=@"未知账号";
    }else{
        NSString *myName=[NSString stringWithFormat:@"%@",_userDic[@"user_profile"][@"nikename"]];
        if (myName.length==0) {
            name.text=@"未知账号";
        }
    }
    
    
    //账号
    UILabel *userAccount=[[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(sexImageView.frame)+10, name.frame.origin.y, self.frame.size.width-CGRectGetMaxX(sexImageView.frame)-10, 20)];
    userAccount.text=_userDic[@"user_profile"][@"phone"];
    userAccount.textColor=[UIColor whiteColor];
    userAccount.font=[UIFont systemFontOfSize:11];
    [view addSubview:userAccount];
    
    if ([_userDic[@"user_profile"][@"phone"] isKindOfClass:[NSNull class]]) {
        userAccount.text=@"= =";
    }else{
        NSString *myName=[NSString stringWithFormat:@"%@",_userDic[@"user_profile"][@"phone"]];
        if (myName.length==0) {
            userAccount.text=@"= =";
        }
    }
    
    
    //年龄
    UILabel *age=[[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(name.frame), (self.frame.size.width-5)/2.0, 20)];
    if ([_userDic[@"user_profile"][@"age"] isKindOfClass:[NSNull class]]) {
        age.text=@"0岁";
    }else{
        age.text=[NSString stringWithFormat:@"%@岁",_userDic[@"user_profile"][@"age"]];
        NSString *myAge=[NSString stringWithFormat:@"%@",_userDic[@"user_profile"][@"age"]];
        NSLog(@"长度%ld",myAge.length);
        if ([myAge isEqualToString:@""]) {
            NSLog(@"相等======");
            age.text=@"0岁";
        }else{
           NSLog(@"不相等======");
            age.text=[NSString stringWithFormat:@"%@岁",_userDic[@"user_profile"][@"age"]];
        }
    }
    
    age.textAlignment=NSTextAlignmentRight;
    age.textColor=[UIColor whiteColor];
    age.font=[UIFont systemFontOfSize:11];
    [view addSubview:age];
    
    
    
    
    //地区
    UILabel *addressLab=[[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(age.frame)+10, age.frame.origin.y, self.frame.size.width-(CGRectGetMaxX(age.frame)+10), 20)];
    addressLab.text=[NSString stringWithFormat:@"%@",_userDic[@"user_profile"][@"city"]];
    addressLab.textColor=[UIColor whiteColor];
    addressLab.font=[UIFont systemFontOfSize:11];
    [view addSubview:addressLab];
    
    if ([_userDic[@"user_profile"][@"city"] isKindOfClass:[NSNull class]]) {
        addressLab.text=@"未知";
    }else{
        NSString *myName=[NSString stringWithFormat:@"%@",_userDic[@"user_profile"][@"city"]];
        if (myName.length==0) {
            addressLab.text=@"未知";
        }
    }
    
    
    
    //标签
    UILabel *biaoqian=[[UILabel alloc]initWithFrame:CGRectMake(sexImageView.frame.origin.x-50, CGRectGetMaxY(age.frame), 30, 20)];
    biaoqian.text=@"标签";
    biaoqian.textColor=[UIColor whiteColor];
    biaoqian.font=[UIFont systemFontOfSize:11];
    [view addSubview:biaoqian];
    if ([_userDic[@"tags"] count]==0) {
        //biaoqian.hidden=YES;
        biaoqian.text=@"标签:   ==       ==";
        biaoqian.frame=CGRectMake(sexImageView.frame.origin.x-50, CGRectGetMaxY(age.frame), 30, 20);
    }
    NSArray *biaoqianArr=_userDic[@"tags"];
    CGFloat biaoqian_w = 0.0;
    
    _allBiaoQianArray=[NSMutableArray array];
    
    for (int i=0; i<biaoqianArr.count; i++) {
        if (i<2) {
            //标签1
            UILabel *biaoqian1=[[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(biaoqian.frame)+2+biaoqian_w+15*i, biaoqian.frame.origin.y, 0, 20)];
            biaoqian1.text=[NSString stringWithFormat:@"%@",biaoqianArr[i][@"name"]];
            [_allBiaoQianArray addObject:[NSString stringWithFormat:@"%@",biaoqianArr[i][@"name"]]];
            biaoqian1.textAlignment=NSTextAlignmentCenter;
            biaoqian1.font=[UIFont systemFontOfSize:11];
            biaoqian1.textColor=[UIColor whiteColor];
            biaoqian1.frame=CGRectMake(CGRectGetMaxX(biaoqian.frame)+2+biaoqian_w+15*i, biaoqian.frame.origin.y, [self calculateWidthWithLable:biaoqian1], 20);
            [view addSubview:biaoqian1];
            biaoqian_w+=[self calculateWidthWithLable:biaoqian1];
        }
    }
    
    //更多标签
    if ([_userDic[@"tags"] count]>0) {
        UIImageView *moreBiaoQianImageView=[[UIImageView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(biaoqian.frame)+2+biaoqian_w+biaoqianArr.count*15, biaoqian.frame.origin.y, 20, 20)];
        moreBiaoQianImageView.image=[UIImage imageNamed:@"baritem_left_hl"];
        [view addSubview:moreBiaoQianImageView];
        //盖按钮
        UIButton *biaoqianBtn=[UIButton buttonWithType:UIButtonTypeCustom];
        biaoqianBtn.frame=CGRectMake(CGRectGetMaxX(biaoqian.frame), biaoqian.frame.origin.y, self.frame.size.width-CGRectGetMaxX(biaoqian.frame), moreBiaoQianImageView.frame.size.height);
        [biaoqianBtn addTarget:self action:@selector(moreBiaoQianBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [view addSubview:biaoqianBtn];
    }
    
    
    
    //个性签名
    UILabel *personalName=[[UILabel alloc]initWithFrame:CGRectMake(biaoqian.frame.origin.x-30, CGRectGetMaxY(biaoqian.frame), self.frame.size.width-((biaoqian.frame.origin.x-30))*2, 20)];
    personalName.text=[NSString stringWithFormat:@"个性签名:%@",_userDic[@"user_profile"][@"signatures"]];
    personalName.textColor=[UIColor whiteColor];
    personalName.font=[UIFont systemFontOfSize:11];
    [view addSubview:personalName];
    personalName.textAlignment=NSTextAlignmentCenter;
    _myPersonalName=personalName.text;
    
    if ([_userDic[@"user_profile"][@"signatures"] isKindOfClass:[NSNull class]]) {
        //personalName.hidden=YES;
        personalName.text=@"个性签名: = =  ";
    }else{
        NSString *myPersonalName=[NSString stringWithFormat:@"%@",_userDic[@"user_profile"][@"signatures"]];
        if (myPersonalName.length==0) {
            personalName.text=@"个性签名: = =  ";
        }
    } 
    
//    NSString *personalStr=_userDic[@"user_profile"][@"signatures"];
//    if (personalStr.length>=20) {
//        
//    }else{
//        personalName.frame=CGRectMake(sexImageView.frame.origin.x-11*2-15, CGRectGetMaxY(biaoqian.frame), self.frame.size.width-name.frame.origin.x+50, 20);
//    }
    
    
    //显示个性签名详情
    UIButton *allPersonalNameBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    allPersonalNameBtn.frame=personalName.frame;
    [allPersonalNameBtn addTarget:self action:@selector(allPersonalNameBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:allPersonalNameBtn];
    
    
    
    
    
    
    //返回上一页
    UIButton *backBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    backBtn.frame=CGRectMake(10, 20, 25, 25);
    [backBtn setBackgroundImage:[UIImage imageNamed:@"left_back"] forState:UIControlStateNormal];
    //[backBtn setTitle:@"返回" forState:UIControlStateNormal];
    //[backBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(backBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:backBtn];
    
    
    //发帖
    UIButton *sendtopicBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    sendtopicBtn.frame=CGRectMake(self.frame.size.width-10-25, 20, 25, 25);
    [sendtopicBtn setBackgroundImage:[UIImage imageNamed:@"shequ_edit"] forState:UIControlStateNormal];
    sendtopicBtn.layer.cornerRadius=25/2.0;
    sendtopicBtn.layer.masksToBounds=YES;
    [sendtopicBtn addTarget:self action:@selector(sendtopicBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:sendtopicBtn];
    
    
    
    
    //我关注的 我的好友  我的粉丝 我的收藏
    
    //我关注的
    CGFloat btn_w=(self.frame.size.width-0.5)/2.0;
    CGFloat btn_h=50;
    UIButton *myCare=[UIButton buttonWithType:UIButtonTypeCustom];
    myCare.frame=CGRectMake(0, CGRectGetMaxY(backgroundImageView.frame), btn_w, btn_h);
    myCare.backgroundColor=[UIColor whiteColor];
    myCare.tag=1;
    [myCare setTitle:@"#我关注的#" forState:UIControlStateNormal];
    [myCare setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [myCare addTarget:self action:@selector(addBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:myCare];
    
    //我的好友
    UIButton *myFriend=[UIButton buttonWithType:UIButtonTypeCustom];
    myFriend.frame=CGRectMake(btn_w+0.5, CGRectGetMaxY(backgroundImageView.frame), btn_w, btn_h);
    myFriend.tag=2;
    myFriend.backgroundColor=[UIColor whiteColor];
    [myFriend setTitle:@"#我的好友#" forState:UIControlStateNormal];
    [myFriend setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [myFriend addTarget:self action:@selector(addBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:myFriend];
    
    //我的粉丝
    UIButton *myFanPage=[UIButton buttonWithType:UIButtonTypeCustom];
    myFanPage.frame=CGRectMake(0, CGRectGetMaxY(backgroundImageView.frame)+0.5+btn_h, btn_w, btn_h);
    myFanPage.backgroundColor=[UIColor whiteColor];
    myFanPage.tag=3;
    [myFanPage setTitle:@"#我的粉丝#" forState:UIControlStateNormal];
    [myFanPage setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [myFanPage addTarget:self action:@selector(addBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:myFanPage];
    
    //我的收藏
    UIButton *myCollection=[UIButton buttonWithType:UIButtonTypeCustom];
    myCollection.frame=CGRectMake(btn_w+0.5, CGRectGetMaxY(backgroundImageView.frame)+0.5+btn_h, btn_w, btn_h);
    myCollection.tag=4;
    myCollection.backgroundColor=[UIColor whiteColor];
    [myCollection setTitle:@"#我的收藏#" forState:UIControlStateNormal];
    [myCollection setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [myCollection addTarget:self action:@selector(addBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:myCollection];
    
    
    view.frame=CGRectMake(0, 0, self.frame.size.width, CGRectGetMaxY(myCollection.frame)+1);
    
//    CGFloat addbtn_w=60;
//    CGFloat addbtn_h=20;
//    UIButton *addBtn1=[UIButton buttonWithType:UIButtonTypeCustom];
//    addBtn1.frame=CGRectMake((self.frame.size.width-addbtn_w)/2.0, CGRectGetMaxY(personalName.frame)+5, addbtn_w, addbtn_h);
//    [addBtn1 setTitle:@"删贴" forState:UIControlStateNormal];
//    addBtn1.titleLabel.font=[UIFont systemFontOfSize:13];
//    addBtn1.backgroundColor=[UIColor colorWithRed:227/255.0 green:105/255.0 blue:136/255.0 alpha:1];
//    addBtn1.layer.borderColor=[UIColor colorWithRed:227/255.0 green:105/255.0 blue:136/255.0 alpha:1].CGColor;;
//    addBtn1.layer.borderWidth=1.0;
//    addBtn1.layer.cornerRadius=3.0;
//    [addBtn1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//    [addBtn1 addTarget:self action:@selector(addBtn1Click:) forControlEvents:UIControlEventTouchUpInside];
//    [view addSubview:addBtn1];
    
    
    return view;
    
}

//删除
-(void)addBtn1Click:(UIButton *)sender
{
    if (isEdited) {
        [sender setTitle:@"完成" forState:UIControlStateNormal];
        [self setEditing:YES animated:YES];
        isEdited=NO;
    }else{
        [sender setTitle:@"删贴" forState:UIControlStateNormal];
        [self setEditing:NO animated:YES];
        isEdited=YES;
        
        //删除帖子
        if (_deleteArray) {
            for (int i=0; i<_deleteArray.count; i++) {
                NSIndexPath *index=(id)_deleteArray[i];
                [_dataArray removeObjectAtIndex:index.row];
                TieZiDetailModel *model=_deleteArray[i];
                [self deleteTopicHttpData:model.topic_id];
            }
            [self reloadData];
            
        }
        
        
    }
    
}



//发帖
-(void)sendtopicBtnClick:(UIButton *)sender
{
    NSLog(@"发帖");
    [self.imgDelegate sendtopicBtnClick];
}

//更多标签按钮点击事件
-(void)moreBiaoQianBtnClick:(UIButton *)sender
{
    [self.imgDelegate moreBiaoQianBtnClick:_allBiaoQianArray];
}

//个性签名完整显示
-(void)allPersonalNameBtnClick:(UIButton *)sender
{
    [self.imgDelegate allPersonalNameBtnClick:_myPersonalName];
}



#pragma mark 我关注的1 我的好友2 我的粉丝3  我的收藏4
-(void)addBtnClick:(UIButton *)sender
{
    // NSLog(@"点击了%ld",sender.tag);
    [self.imgDelegate chooseFunction:sender.tag];
}
#pragma mark 返回上一页
-(void)backBtnClick:(UIButton *)sender
{
    [self.imgDelegate gotoUpViewController];
}
//tableView的代理方法
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    for (id subView in cell.contentView.subviews) {
        [subView removeFromSuperview];
    }
    cell.backgroundColor=[UIColor whiteColor];
    
    TieZiDetailModel *model=_dataArray[indexPath.row];
    //cell.userInteractionEnabled=NO;
    //用户头像
    UIImageView *headImageView=[[UIImageView alloc]initWithFrame:CGRectMake(10, 20, 56, 56)];
    //headImageView.image=[UIImage imageNamed:_dataArray[indexPath.row][@"userHeadImage"]];
    [headImageView sd_setImageWithURL:[NSURL URLWithString:model.user_info[@"avatar_url"]] placeholderImage:[UIImage imageNamed:@"155x155-1.png"]];
    headImageView.layer.cornerRadius=56/2.0;
    headImageView.layer.masksToBounds=YES;
    [cell.contentView addSubview:headImageView];
    
    
    NSData *data=[NSData dataWithContentsOfURL:[NSURL URLWithString:model.user_info[@"avatar_url"]]];
    UIImage *myHeadImage=[UIImage imageWithData:data];
    headImageView.image=myHeadImage;
    
    
    if (indexPath.row==0) {
         headImageView.frame=CGRectMake(headImageView.frame.origin.x, headImageView.frame.origin.y-5, headImageView.frame.size.width, headImageView.frame.size.height);
    }
    
    
    
    
    //盖按钮
    UIButton *headImageBtn1=[UIButton buttonWithType:UIButtonTypeCustom];
    headImageBtn1.frame=headImageView.frame;
    [headImageBtn1 addTarget:self action:@selector(headImageBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [cell.contentView addSubview:headImageBtn1];
    
    
    CGFloat height=(56-8)/3.0;
    //用户名
    UILabel *name=[[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(headImageView.frame)+8, headImageView.frame.origin.y, 80, height)];
    name.text=model.user_info[@"nikename"];
    name.textColor=[UIColor colorWithRed:87/255.0 green:194/255.0 blue:209/255.0 alpha:1];
    name.font=[UIFont systemFontOfSize:13];
    name.frame=CGRectMake(CGRectGetMaxX(headImageView.frame)+8, headImageView.frame.origin.y, [self calculateWidthWithLable:name], height);
    [cell.contentView addSubview:name];
    
    //性别
    UIImageView *sexImageView=[[UIImageView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(name.frame)+2, headImageView.frame.origin.y, height, height)];
    //sexImageView.image=[UIImage imageNamed:_dataArray[indexPath.row][@"sex"]];
    [cell.contentView addSubview:sexImageView];
    NSInteger sexState=[model.user_info[@"sex"] integerValue];
    if (sexState==0) {
        sexImageView.image=[UIImage imageNamed:@"sex_man"];
    }else{
        sexImageView.image=[UIImage imageNamed:@"sex_woman"];
    }
    //    UILabel *sex=[[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(name.frame)+2, 10, 10, height)];
    //    sex.text=_dataArray[indexPath.row][@"sex"];
    //    sex.textColor=[UIColor colorWithRed:87/255.0 green:194/255.0 blue:209/255.0 alpha:1];
    //    sex.font=[UIFont systemFontOfSize:10];
    //    [cell.contentView addSubview:sex];
    
    //标签
    UILabel *biaoqian=[[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(headImageView.frame)+8, CGRectGetMaxY(name.frame)+4, 40, height)];
    biaoqian.text=model.tag_name;
    biaoqian.textColor=[UIColor colorWithRed:87/255.0 green:194/255.0 blue:209/255.0 alpha:1];
    biaoqian.font=[UIFont systemFontOfSize:12];
    biaoqian.layer.borderColor=[UIColor colorWithRed:87/255.0 green:194/255.0 blue:209/255.0 alpha:1].CGColor;
    biaoqian.layer.borderWidth=1.0;
    biaoqian.layer.cornerRadius=2.0;
    biaoqian.textAlignment=NSTextAlignmentCenter;
    biaoqian.frame=CGRectMake(biaoqian.frame.origin.x, biaoqian.frame.origin.y, [self calculateWidthWithLable:biaoqian]+8, biaoqian.frame.size.height);
    [cell.contentView addSubview:biaoqian];
    
    //时间
    UILabel *time=[[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(headImageView.frame)+8, CGRectGetMaxY(biaoqian.frame)+4, 60, height)];
    time.text=model.created_at;
    time.textColor=[UIColor colorWithRed:87/255.0 green:194/255.0 blue:209/255.0 alpha:1];
    time.font=[UIFont systemFontOfSize:13];
    time.frame=CGRectMake(time.frame.origin.x, time.frame.origin.y, [self calculateWidthWithLable:time], time.frame.size.height);
    [cell.contentView addSubview:time];
    
    
    //CGFloat height2=56/3.0;
    
    //评论
    UIImageView *commentImageView=[[UIImageView alloc]initWithFrame:CGRectMake(self.frame.size.width-10-30-20-30-20-1, headImageView.frame.origin.y, 20, 20)];
    commentImageView.image=[UIImage imageNamed:@"shequ_comment.png"];
    [cell.contentView addSubview:commentImageView];
    
    
    
    UILabel *commentLab=[[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(commentImageView.frame)+1, headImageView.frame.origin.y, 30, 20)];
    commentLab.text=[self getLabel:model.comment_num];
    
    commentLab.font=[UIFont systemFontOfSize:10];
    commentLab.textColor=[UIColor grayColor];
    [cell.contentView addSubview:commentLab];
    
    
    
    //点赞
    UIImageView *zanImageView=[[UIImageView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(commentLab.frame), headImageView.frame.origin.y, 20, 20)];
    //NSInteger zanState=[_dataArray[indexPath.row][@"zanState"] integerValue];
    NSInteger zanState=[model.is_like integerValue];
    if (zanState==0) {
        zanImageView.image=[UIImage imageNamed:@"shequ_dianzan_no.png"];
    }else{
        zanImageView.image=[UIImage imageNamed:@"shequ_dianzan_yes.png"];
    }
    //添加手势
    zanImageView.userInteractionEnabled=YES;
    zanImageView.tag=indexPath.row+1;
    
    
    UITapGestureRecognizer *tap1=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapHappen1:)];
    [zanImageView addGestureRecognizer:tap1];
    
    
    [cell.contentView addSubview:zanImageView];
    
    if (tiebaAnimationState==1) {
        CAKeyframeAnimation *k = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"];
        k.values = @[@(0.1),@(1.0),@(1.5)];
        k.keyTimes = @[@(0.0),@(0.5),@(0.8),@(1.0)];
        k.calculationMode = kCAAnimationLinear;
        [zanImageView.layer addAnimation:k forKey:@"SHOW"];
    }
    
    
    UILabel *zanLab=[[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(zanImageView.frame)+1, headImageView.frame.origin.y, 30, 20)];
    zanLab.text=[self getLabel:model.like_num];
    zanLab.font=[UIFont systemFontOfSize:10];
    zanLab.textColor=[UIColor grayColor];
    [cell.contentView addSubview:zanLab];
    
    
    //精华帖标识
    UIImageView *jinghuatie=[[UIImageView alloc]initWithFrame:CGRectMake(commentImageView.frame.origin.x, CGRectGetMaxY(commentImageView.frame)+3, 20+30+2+20+30, 34*(102/168.0))];
        jinghuatie.image=[UIImage imageNamed:@"tieziImage_01"];
    if ([model.is_popular integerValue]!=0) {
        jinghuatie.image=[UIImage imageNamed:@"tieziImage_02"];
    }
    if ([model.is_great integerValue]!=0) {
        jinghuatie.image=[UIImage imageNamed:@"tieziImage_03"];
    }
    [cell.contentView addSubview:jinghuatie];
    
    
    //帖子标题
    UILabel *topicLab=[[UILabel alloc]initWithFrame:CGRectMake(10, CGRectGetMaxY(headImageView.frame)+5, self.frame.size.width-10-10, 100-10-50)];
    topicLab.text=model.title;
    topicLab.textColor=[UIColor blackColor];
    topicLab.font=[UIFont systemFontOfSize:15];
    topicLab.numberOfLines=0;
    CGSize topicLabSize=[topicLab boundingRectWithSize:CGSizeMake(topicLab.frame.size.width, 0)];
    topicLab.frame=CGRectMake(10, CGRectGetMaxY(headImageView.frame)+5, self.frame.size.width-10-10, topicLabSize.height);
    
    [cell.contentView addSubview:topicLab];
    
    
    //帖子内容
    UILabel *contentLab=[[UILabel alloc]initWithFrame:CGRectMake(10, CGRectGetMaxY(topicLab.frame)+5, self.frame.size.width-10-10, 112-10-50-40-1)];
    contentLab.text=model.content;
    contentLab.textColor=[UIColor blackColor];
    contentLab.font=[UIFont systemFontOfSize:13];
    contentLab.numberOfLines=0;
    CGSize contentLabsize=[contentLab boundingRectWithSize:CGSizeMake(contentLab.frame.size.width, 0)];
    contentLab.frame=CGRectMake(10, CGRectGetMaxY(topicLab.frame)+5, self.frame.size.width-10-10, contentLabsize.height);
    
    [cell.contentView addSubview:contentLab];

    
    
    
    //发表的图片
    CGFloat img_w=(self.frame.size.width-10*6)/5.0;
    CGFloat img_h=img_w*1.1;
    NSInteger hang=[self calculatingHang:model.media_urls];
    //NSLog(@"图片有多少行=====%ld",hang);
    for (int i=0; i<hang; i++) {
        for (int j=0; j<5; j++) {
            if (i*5+j<[model.media_urls count]) {
                UIImageView *imgView=[[UIImageView alloc]initWithFrame:CGRectMake(10+(img_w+10)*j, CGRectGetMaxY(contentLab.frame)+10+(img_h+5)*i, img_w, img_h)];
                //imgView.image=[UIImage imageNamed:_dataArray[indexPath.row][@"imageArr"][i*5+j]];
                [imgView sd_setImageWithURL:[NSURL URLWithString:model.media_urls[i*5+j]] placeholderImage:[UIImage imageNamed:@"noImage_background"]];
                 [cell.contentView addSubview:imgView];
                imgView.tag=1000*indexPath.row+i*5+j;
                
                UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(imgTapHappen:)];
                imgView.userInteractionEnabled=YES;
                [imgView addGestureRecognizer:tap];
            }
        }
    }
    if ([model.media_urls count]>0) {
        UIView *line=[[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(contentLab.frame)+10+img_h+9, self.frame.size.width, 1)];
        line.backgroundColor=[UIColor colorWithRed:212/255.0 green:213/255.0 blue:214/255.0 alpha:1];
        [cell.contentView addSubview:line];
        if (hang==1) {
            line.frame=CGRectMake(0, CGRectGetMaxY(contentLab.frame)+10+img_h+9, self.frame.size.width, 1);
        }else if (hang==2){
            line.frame=CGRectMake(0, CGRectGetMaxY(contentLab.frame)+10+img_h*2+5+9, self.frame.size.width, 1);
        }
    }else{
        UIView *line=[[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(contentLab.frame)+9, self.frame.size.width, 1)];
        line.backgroundColor=[UIColor colorWithRed:212/255.0 green:213/255.0 blue:214/255.0 alpha:1];
        [cell.contentView addSubview:line];
    }
    
    //cell.selectionStyle=UITableViewCellSelectionStyleNone;
    
    
    
    
    
    return cell;
}

//UIScrollView的代理
-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    tiebaAnimationState=0;
}


//点击发表的图片
-(void)imgTapHappen:(UITapGestureRecognizer *)tap
{
    UIImageView *imgView=(id)tap.view;
    NSLog(@"手势响应了");
    TieZiDetailModel *model=_dataArray[imgView.tag/1000];
    //[self.imgDelegate bigImage:imgView.image];
    [self.imgDelegate bigImage:imgView.tag%1000 AndImageArrays:model.media_urls];
}


#pragma mark 删除帖子
-(void)deleteCellBtnClick:(UIButton *)sender
{
    [_dataArray removeObjectAtIndex:_cellIndex-1];
    [self reloadData];
}

#pragma mark 取消
-(void)cancelCellBtnClick:(UIButton *)sender
{
    UIView *view=(id)[self viewWithTag:_cellIndex];
    view.hidden=YES;
}
-(void)btnClick1:(UIButton *)sender
{
    NSLog(@".........................");
}
//计算评论 点赞的个数
-(NSString *)getLabel:(NSString *)number
{
    NSInteger num=[number floatValue];
    if (num>10000) {
        number=[NSString stringWithFormat:@"%.1f万",num/10000.0];
    }
    return number;
    
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    TieZiDetailModel *model=_dataArray[indexPath.row];
    //帖子标题
    UILabel *topicLab=[[UILabel alloc]initWithFrame:CGRectMake(10, 0, self.frame.size.width-10-10, 100-10-50)];
    topicLab.text=model.title;
    topicLab.textColor=[UIColor blackColor];
    topicLab.font=[UIFont systemFontOfSize:15];
    topicLab.numberOfLines=0;
    CGSize topicLabSize=[topicLab boundingRectWithSize:CGSizeMake(topicLab.frame.size.width, 0)];
    
    //帖子内容
    UILabel *contentLab=[[UILabel alloc]initWithFrame:CGRectMake(10, CGRectGetMaxY(topicLab.frame), self.frame.size.width-10-10, 112-10-50-40-1)];
    contentLab.text=model.content;
    contentLab.textColor=[UIColor blackColor];
    contentLab.font=[UIFont systemFontOfSize:13];
    contentLab.numberOfLines=0;
    CGSize contentLabsize=[contentLab boundingRectWithSize:CGSizeMake(contentLab.frame.size.width, 0)];
    //发表的图片
    CGFloat img_w=(self.frame.size.width-10*6)/5.0;
    CGFloat img_h=img_w*1.1;
    if ([model.media_urls count]>0) {
        NSInteger hang=[self calculatingHang:model.media_urls];
        if (hang==1) {
            if (indexPath.row==0) {
                return 60+30+img_h+10+topicLabSize.height+contentLabsize.height-5;
            }else{
                return 60+30+img_h+10+topicLabSize.height+contentLabsize.height;
            }
            
        }else if (hang==2){
            if (indexPath.row==0) {
                return 60+30+img_h*2+5+10+topicLabSize.height+contentLabsize.height-5;
            }else{
                return 60+30+img_h*2+5+10+topicLabSize.height+contentLabsize.height;
            }
            
        }
        
    }
    
    if (indexPath.row==0) {
       return 60+30+topicLabSize.height+contentLabsize.height-5;
    }else{
        return 60+30+topicLabSize.height+contentLabsize.height;
    }
    
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (isEdited) {
       // [self.imgDelegate gotoXiangQingViewController:_arr];
        TieZiDetailModel *model=_dataArray[indexPath.row];
        [self.imgDelegate gotoXiangQingViewController:[model.topic_id integerValue]];
    }else{
        [_deleteArray addObject:indexPath];
    }
    
}
//根据文字计算宽度和高度
-(CGFloat)calculateWidthWithLable:(UILabel *)label
{
    CGSize size=[label.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:label.font,NSFontAttributeName, nil]];
    return size.width;
}


//头像按钮的响应
-(void)headImageBtnClick:(UIButton *)sender
{
    NSLog(@"头像");
    //进入我关注的界面
    //[self.imgDelegate gotoMyAttentionViewController];
}

//点赞
-(void)zanImageBtnClick:(UIButton *)sender
{
    NSLog(@"点赞");
}

//发表的图片
-(void)imgBtnClick:(UIButton *)sender
{
    NSLog(@"图片响应");
    //[self.imgDelegate bigImage:sender.imageView.image];
}
//计算行
-(NSInteger)calculatingHang:(NSArray *)arr
{
    NSInteger hang=0;
    if (arr.count>5) {
        hang=2;
    }else if(arr.count==0){
        hang=0;
    }else{
        hang=1;
    }
    return hang;
}
//点赞
//点赞
-(void)tapHappen1:(UITapGestureRecognizer *)tap
{
    UIImageView *imgView=(id)tap.view;
    NSLog(@"=========%ld",imgView.tag-1);
    TieZiDetailModel *model1=_dataArray[imgView.tag-1];
    tiebaAnimationState=1;
    
    NSInteger zanState=[model1.is_like integerValue];
    CAKeyframeAnimation *k = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"];
    k.values = @[@(0.1),@(1.0),@(1.5)];
    k.keyTimes = @[@(0.0),@(0.5),@(0.8),@(1.0)];
    k.calculationMode = kCAAnimationLinear;
    if (zanState==0) {
        //点赞
        imgView.layer.contents=(id)[UIImage imageNamed:@"shequ_dianzan_yes"].CGImage;
        
        NSLog(@"点赞");
        
        NSDictionary *dic=_tieziDataArray[imgView.tag-1];
        NSInteger zanNumber=[dic[@"like_num"] integerValue];
        zanNumber+=1;
        [dic setValue:@"1" forKey:@"is_like"];
        [dic setValue:[NSString stringWithFormat:@"%ld",zanNumber] forKey:@"like_num"];
        TieZiDetailModel *model2=[[TieZiDetailModel alloc]initWithDictionary:dic];
        
        [_dataArray removeObjectAtIndex:imgView.tag-1];
        [_dataArray insertObject:model2 atIndex:imgView.tag-1];
        
        [_tieziDataArray removeObjectAtIndex:imgView.tag-1];
        [_tieziDataArray insertObject:dic atIndex:imgView.tag-1];
        
        //一个cell刷新
        NSIndexPath *indexPath=[NSIndexPath indexPathForRow:imgView.tag-1 inSection:0];
        [self reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
        
        //通知后台
        TieZiDetailModel *model3=_dataArray[imgView.tag-1];
        [self getZanHttpData:model3.topic_id];
        
    }else{
        //取消赞
        imgView.layer.contents=(id)[UIImage imageNamed:@"shequ_dianzan_no"].CGImage;
        NSLog(@"取消赞");
        
        NSDictionary *dic=_tieziDataArray[imgView.tag-1];
        [dic setValue:@"0" forKey:@"is_like"];
        NSInteger zanNumber=[dic[@"like_num"] integerValue];
        zanNumber-=1;
        [dic setValue:[NSString stringWithFormat:@"%ld",zanNumber] forKey:@"like_num"];
        TieZiDetailModel *model2=[[TieZiDetailModel alloc]initWithDictionary:dic];
        
        [_dataArray removeObjectAtIndex:imgView.tag-1];
        [_dataArray insertObject:model2 atIndex:imgView.tag-1];
        
        [_tieziDataArray removeObjectAtIndex:imgView.tag-1];
        [_tieziDataArray insertObject:dic atIndex:imgView.tag-1];
        
        //一个cell刷新
        NSIndexPath *indexPath=[NSIndexPath indexPathForRow:imgView.tag-1 inSection:0];
        [self reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
        
        //通知后台
        TieZiDetailModel *model3=_dataArray[imgView.tag-1];
        [self getCancelZanHttpData:model3.topic_id];
    }
    [imgView.layer addAnimation:k forKey:@"SHOW"];
    
}




//////////////////
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewCellEditingStyleDelete | UITableViewCellEditingStyleInsert;
}


//获取个人信息
-(void)getMyHttpData
{
    AFHTTPRequestOperationManager *manager=[AFHTTPRequestOperationManager manager];
    manager.requestSerializer=[AFHTTPRequestSerializer serializer];
    manager.responseSerializer=[AFHTTPResponseSerializer serializer];
    
    NSUserDefaults *user=[NSUserDefaults standardUserDefaults];
    NSString *userId=[user objectForKey:@"userId"];
    NSString *token=[user objectForKey:@"token"];
    
    [manager GET:[NSString stringWithFormat:PersonalHomeMessage,userId,token] parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        [self.header endRefreshing];
        NSDictionary *dic=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
        NSLog(@"个人信息=====%@",dic);
        if (dic) {
            _userDic=dic[@"user"];
            _userDic=[NSDictionary changeType:_userDic];
            _tieziDataArray=dic[@"topics"][@"data"];
            NSLog(@"用户的信息=====%@",_userDic);
            _dataArray=[NSMutableArray array];
            
            _nextPageUrl=dic[@"topics"][@"next_page_url"];
            
            if ([dic[@"topics"][@"next_page_url"] isKindOfClass:[NSNull class]]) {
                _nextPageUrl=nil;
            }else{
                _nextPageUrl=dic[@"topics"][@"next_page_url"];
            }
            
            for (NSDictionary *dataDic in dic[@"topics"][@"data"]) {
                TieZiDetailModel *model=[[TieZiDetailModel alloc]initWithDictionary:dataDic];
                [_dataArray addObject:model];
                NSLog(@"zanState=================%@",dataDic[@"is_like"]);
            }
            
            dispatch_async(dispatch_get_main_queue(), ^{
                self.tableHeaderView=[UIView new];
                self.tableHeaderView=[self createTableHeaderView];
                [self reloadData];
            });
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        [self.header endRefreshing];
        NSLog(@"error====%@",error.localizedDescription);
    }];
    
}
//删帖
-(void)deleteTopicHttpData:(NSString *)topicId
{
    AFHTTPRequestOperationManager *manager=[AFHTTPRequestOperationManager manager];
    manager.requestSerializer=[AFHTTPRequestSerializer serializer];
    manager.responseSerializer=[AFHTTPResponseSerializer serializer];
    
    NSUserDefaults *user=[NSUserDefaults standardUserDefaults];
    NSString *token=[user objectForKey:@"token"];
    
    
    [manager DELETE:[NSString stringWithFormat:DeleteTopic,token,topicId] parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSDictionary *dic=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
        NSLog(@"deleteTopic==%@",dic);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"error%@",error.localizedDescription);
    }];
}


//下拉加载
-(void)getMoreData
{
    
    AFHTTPRequestOperationManager *manager=[AFHTTPRequestOperationManager manager];
    manager.requestSerializer=[AFHTTPRequestSerializer serializer];
    manager.responseSerializer=[AFHTTPResponseSerializer serializer];
    if (_nextPageUrl.length) {
        [manager GET:_nextPageUrl parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
            [self.footer endRefreshing];
            NSDictionary *dic=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
            NSLog(@"个人信息=====%@",dic);
            if (dic) {
                
                if ([dic[@"topics"][@"next_page_url"] isKindOfClass:[NSNull class]]) {
                    _nextPageUrl=nil;
                }else{
                    _nextPageUrl=dic[@"topics"][@"next_page_url"];
                }
                
                for (NSDictionary *dataDic in dic[@"topics"][@"data"]) {
                    TieZiDetailModel *model=[[TieZiDetailModel alloc]initWithDictionary:dataDic];
                    [_dataArray addObject:model];
                    [_tieziDataArray addObject:dataDic];
                    NSLog(@"zanState=================%@",dataDic[@"is_like"]);
                }
                
                dispatch_async(dispatch_get_main_queue(), ^{
                    [self reloadData];
                });
            }
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
             [self.footer endRefreshing];
            NSLog(@"error====%@",error.localizedDescription);
        }];

    }else{
         [self.footer endRefreshing];
        return;
    }
    
   
}






///帖子点赞
-(void)getZanHttpData:(NSString *)tieziId
{
    NSLog(@"帖子的id======%@",tieziId);
    AFHTTPRequestOperationManager *manager=[AFHTTPRequestOperationManager manager];
    manager.requestSerializer=[AFHTTPRequestSerializer serializer];
    manager.responseSerializer=[AFHTTPResponseSerializer serializer];
    NSUserDefaults *user=[NSUserDefaults standardUserDefaults];
    NSString *token=[user objectForKey:@"token"];
    
    
    [manager POST:[NSString stringWithFormat:@"%@?token=%@&topic_id=%@",TieZiIsLike,token,tieziId] parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSDictionary *dic=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
        NSLog(@"tieziZanData===============%@点赞结果========%@",dic,dic[@"status"][@"msg"]);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"%@",error.localizedDescription);
    }];
}
//取消点赞
-(void)getCancelZanHttpData:(NSString *)tieziId
{
    NSLog(@"帖子的id======%@",tieziId);
    AFHTTPRequestOperationManager *manager=[AFHTTPRequestOperationManager manager];
    manager.requestSerializer=[AFHTTPRequestSerializer serializer];
    manager.responseSerializer=[AFHTTPResponseSerializer serializer];
    NSUserDefaults *user=[NSUserDefaults standardUserDefaults];
    NSString *token=[user objectForKey:@"token"];
    
    
    [manager DELETE:[NSString stringWithFormat:@"%@?token=%@&topic_id=%@",TieZiCancellike,token,tieziId] parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSDictionary *dic=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
        NSLog(@"tieziCancelZanData===============%@=====取消赞结果======%@",dic,dic[@"status"][@"msg"]);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"%@",error.localizedDescription);
    }];
}

@end









